<!DOCTYPE html>
<html lang="zh-CN">
<head>
 
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
 
 
	    
    <script>
        var curent_page=${currentpage};
 
        function doDeleteTableRow()
        {
 
    		var index=$(".list-checkbox:checked").size();
    		if(index==0){
    			jAlert("未勾选要删除的对象");
    		}else{
    			jConfirm('确定删除选中的对象?', '提示', function(r) {
 				   if(r==true){
    				$("#searchform").attr("action","${base}/batchdel_admin_user?idStr="+getCheckedIds());
    		    	$("#searchform").submit();
 				   }
				});
    		}
            return true;
        }
 
        var addformv,editformv;
        jQuery(document).ready(function()
        {
            var optInit = getOptionsFromForm();
            $("#Pagination").pagination(${totalRecord}, optInit);
            App.init();
            combox("addProvince","Province",null,null,false);
            combox("addCity","City",$("#addProvince").val(),null,false);
            combox("editProvince","Province",null,null,false);
            combox("editCity","City",$("#editProvince").val(),null,false);
            
            combox("addRole","Role",null,null,false);
            combox("editRole","Role",null,null,false);
            addformv=$("#addForm").validate();
            editformv=$("#editForm").validate();
        });
 
        function doTableSort(ID)
        {
            $("#postsortfield").val(ID);
            $("#currentpage").val(0);
            $("#searchform").submit();
        }
        
        
        function addEntity(){
      	    
        	    addformv.form();
        	    if(addformv.valid()){
	                var a ;
	                var nowtime = new Date();
	                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
	                a=strtemp;

        	          $.getJSON("${base}/add_admin_user/" + a+
                              "?"+$("#addForm").serialize()
                      ,
                      function(data)
                      {
                          if(data ==1) {
                        	  jAlert("添加成功！");
                              window.location.reload();
                          }
                          else if(data ==-1)
                        	  jAlert("未知错误！");
                      });	
        	    	
        	    }

        }
        
         
        function showEditDiv(id) 
        {
       	  $("#loading").showLoading(); 
      	  $.ajax({  
      	        type : "POST",  
      	        url : CONTEXT+'/get_adminuser_by_id?id='+id,  
      	        dataType : "json",  
      	        cache : false,  
      	        async : false,  
      	        success : function(data) {  
      	       
      	      	    $("#editDiv #editId").val(data.id);
     	        	$("#editDiv #editPhone").val(data.phone);
      	        	$("#editDiv #editEmail").val(data.email);
      	        	$("#editDiv #editLoginName").val(data.loginname);
      	        	$("#editDiv #editUserName").val(data.username);
	      	        $("#editDiv #editRole option[value='"+data.roleId+"']").attr("selected", true);  
	      	        $("#editDiv #editCompany option[value='"+data.companytype+"-"+data.companyid+"']").attr("selected", true);  
	      	        $("#editDiv #editProvince option[value='"+data.provinceid+"']").attr("selected", true);  
	      	        $("#editDiv #editProvince").trigger("change");
	      	        $("#editDiv #editCity option[value='"+data.cityid+"']").attr("selected", true);  
	      	        $('#loading').hideLoading();
		      	    showPopup("editDiv");
      	        
      	        }  
      	    }); 
        	
        }
        
        function showPopup(div) 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var realDiv = document.getElementById(div);
            realDiv.style.top = "10%";//设置弹出层距离上边界的距离
            realDiv.style.left = "30%";//设置弹出层距离左边界的距离
            realDiv.style.width = "40%";//设置弹出层的宽度
            realDiv.style.height = "auto";//设置弹出层的高度
            realDiv.style.visibility = "visible";
        }
        	     
        
        function  updateEntity(){
        	
	    	 editformv.form();
	   	     if(editformv.valid()){
	   	    	 $("#loading").showLoading(); 
	             $.ajax({  
	       	        type : "POST",  
	       	        url : CONTEXT+'/edit_admin_user',  
	       	        data: $("#editForm").serialize(),
	       	        dataType : "json",  
	       	        success : function(data) {  
	       	           $('#loading').hideLoading();
	       	        	if(data.result==true){
	                        window.location.reload();
	       	        	}else{
	       	        		jAlert(data.msg);
	       	        	}
	       	        	
	       	        }  
	       	    }); 
	   	     }
       }
       
 
 
        function hidePopup() 
        {//关闭层
  
         	addformv.resetForm();
        	editformv.resetForm();
 
            var realDiv = document.getElementById("editDiv");
            realDiv.style.visibility = "hidden";
   
        	
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var realDiv = document.getElementById("realDiv");
            realDiv.style.visibility = "hidden";
        }
   

    </script>
  
</head>

<body>

<div id="backDiv" onclick="hidePopup()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

<div id="realDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="padding: 0px;margin:0px;">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-plus"></i>添加管理员</div>
                <a href="javascript:allDivHide();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
                <form id="addForm"   method="POST">
                    <table class="table-bordered table-striped table-condensed flip-content">
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                        
                         <tr class="even">
                            <td style="text-align: right;">省份<span class="fill-must">*</span></td>
                            <td class="even">
		                            <div class="m-wrap span8 sheet-selectTwoBar">
								        <select class="form-control" id="addProvince"  name="provinceid" onchange="combox('addCity','City',$(this).val(),null,false)" required>
										</select>
								    </div>
                            </td>
                            <td style="text-align: right;">地市<span class="fill-must">*</span></td>
                            <td class="even">
								    <div class="m-wrap span8">
								        <select class="form-control" id="addCity" name="cityid" required>
										</select>
								    </div>
                            </td>
                        </tr>
       
                        <tr class="odd">
                            <td style="text-align: right;">登录邮箱<span class="fill-must">*</span></td>
                            <td class="center">
                                 <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addEmail" name="email" data-rule-email="true" placeholder="请输入邮箱" required/>
                            </td>
                            <td style="text-align: right;">登录名<span class="fill-must">*</span></td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addLoginname" name="loginname"  placeholder="请输入登录名" 
                                   required  data-rule-loginname="true" data-rule-remote="${base}/checkNameUnique?category=AdminUserName&where=and del=0" data-msg-remote="登录名已存在" onkeyup="editformv.form();"/>
                            </td>
                        </tr>
   
                        <tr class="even">
                            <td style="text-align: right;">手机号<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addPhone" name="phone" required data-rule-mobile="true" data-msg-mobile="请输入正确格式" placeholder="请输入手机号" />
                            </td>
                            <td style="text-align: right;">姓名
                            <span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addUserName" name="username" required  placeholder="请输入用户名" />
                            </td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: right;">密码<span class="fill-must">*</span></td>
                            <td class="center">
                                <input onchange="$('#md5password').val($.md5($('#addPassword').val()))" class="m-wrap span8" style="margin-top: 10px" type="password" id="addPassword"  required  minLength="4"  data-msg-minLength="请至少输入4个字符"  placeholder="请输入密码"/>
                                <input type="hidden" id="md5password" name="password"  />
                            </td>
                            <td style="text-align: right;">确认密码<span class="fill-must">*</span></td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="password" id="addPassword2" name="password2" required  equalTo="#addPassword" data-msg-equalTo="两次输入的密码不一致" placeholder="请再次输入密码"/>
                            </td>
                        </tr>
                    
                        <tr class="even">
                            <td style="text-align: right;">所属公司<span class="fill-must">*</span></td>
                            <td class="center">
                                <select id="addCompany" name="companyStr" class="m-wrap span8" value="<#if addCompany??>${addCompany}</#if>" style="margin-top: 10px" required placeholder="">
                                <option value="">===请选择===</option>
                                <#if companyList??>
	                                <#list companyList as clist> 
	                                    <option value="${clist.getKey()}"><#if clist.getName()??>${clist.getName()}</#if></option>
	                                </#list>
                                  </#if>
                                </select>
                            </td>
                            
                            <td style="text-align: right;">角色<span class="fill-must">*</span></td>
                            <td class="center">
                                <select id="addRole" name="roleId" class="m-wrap span8" value="<#if addRole??>${addRole}</#if>" style="margin-top: 10px" required placeholder="">
                                </select>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="提交" class="btn green" onclick="addEntity()"/>
                        <input type="button" value="取消" class="btn green" onclick="hidePopup()" />
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div id="editDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="margin: -1px;">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-edit"></i>编辑管理人员</div>
                <a href="javascript:hideEditTable();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
              <form id="editForm" action="<@spring.url '/edit_admin_user'></@spring.url>" method="POST">
              <table class="table-bordered table-striped table-condensed flip-content">
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                        <input   type="hidden" id="editId" name="id" />
                         <tr class="even">
                            <td style="text-align: right;">地区<span class="fill-must">*</span></td>
                            <td class="even">
		                            <div class="m-wrap span4 sheet-selectTwoBar">
								        <select class="form-control" id="editProvince" name="provinceid" onchange="combox('editCity','City',$(this).val(),null,false)" required>
										</select>
								    </div>
								    <div class="m-wrap span4">
								        <select class="form-control" id="editCity" name="cityid" required>
										</select>
								    </div>
                            </td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: right;">登录邮箱<span class="fill-must">*</span></td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="editEmail" name="email" data-rule-email="true" placeholder="请输入邮箱" required/>
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">登录名<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="editLoginName" name="loginname" placeholder="请输入登录名" required/>
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">姓名<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="editUserName" name="username" placeholder="请输入用户名" required/>
                            </td>
                        </tr>
                        <tr class="odd">
                            <td style="text-align: right;">手机号<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="editPhone" name="phone" required data-rule-mobile="true" data-msg-mobile="请输入正确电话格式" placeholder="请输入手机号"/>
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">所属公司<span class="fill-must">*</span></td>
                            <td class="center">
                                <select id="editCompany"   name="companyStr" class="m-wrap span8"   style="margin-top: 10px" placeholder="" required>
                                  <option value="">===请选择===</option>
                                  <#if companyList??>
	                                <#list companyList as clist> 
	                                    <option value="${clist.getKey()}"><#if clist.getName()??>${clist.getName()}</#if></option>
	                                </#list>
                                  </#if>
                                </select>
                            </td>
                        </tr>

                        <tr class="even">
                            <td style="text-align: right;">角色<span class="fill-must">*</span></td>
                            <td class="center">
                                <select id="editRole" name="roleId" class="m-wrap span8" value="<#if editRole??>${editRole}</#if>" style="margin-top: 10px" placeholder="" required>
                                </select>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                    
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="提交" class="btn green" onclick="updateEntity()"/>
                        <input type="button" value="取消" class="btn green" onclick="hidePopup()" />
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="page-container row-fluid">

<#include "bases/sidebar.ftl">
<#include "bases/navhead.ftl">

    <div class="page-content secMenu-content" id="loading">
     
        <div class="container-fluid">
 
            <div class="row-fluid">
                <div class="span12">
                    <div class="portlet box green">
                        <div class="portlet-title">
                            <div class="caption"><i class="fa fa-cogs"></i>管理人员列表</div>
                            <div class="tools">
                                <a href="javascript:window.location.reload()" class="reload"></a>
                            </div>                            
                        </div>
                        <div class="portlet-body flip-scroll">
                            <form id="searchform" action="${base}/admin_user_manage" method="POST">
                               
                                <div class="controls controls-row">
                                    <input  name="loginname" type="text" class="form-control sheet-searchInput" id="loginname" value="<#if loginname??>${loginname}</#if>" placeholder="登录名称"/>
                                   
                                    <button type="submit" class="btn blue" onclick="searchButton()">搜索 </button>
                                   
                                    <input  type="hidden" id="currentpage" name="page" value="0" />
                                    <input  type="hidden" id="postsortfield" name="sortfield" value="<#if sortfield??>${sortfield}</#if>" />
                             
                                </div>
                                <div class="controls controls-row" style="margin-top: 20px">
                                    <button  type="button" class="btn green" onclick="showPopup('realDiv')"><i class="fa fa-plus"></i>增加用户</button>
                                    <button  type="button" class="btn blue" onclick="doDeleteTableRow()">批量删除</button>
 
                                </div>
                                <table  class="table table-bordered table-hover table-striped table-condensed list-table">
                                    <thead class="flip-content">
                                    <tr>
                                        <th><input type="checkbox"  class="checkbox-length list-checkboxAll" value="-1"></th>
                                        <th style="text-align: center;" onclick="javascript:doTableSort('loginname')">登录名称</th>
                                        <th style="text-align: center;">姓名</th>
                                        <th style="text-align: center;">手机号</th>
                                        <th style="text-align: center;">地区</th>
                                        <th style="text-align: center;" onclick="javascript:doTableSort('companyname')">所属公司</th>
                                        <th style="text-align: center;">角色</th>
                                        <th style="text-align: center;width: 150px">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list admin_users as aus>
                                    <tr>
                                        <th><input type="checkbox" class="list-checkbox" value="<#if aus.getId()??>${aus.getId()}</#if>"></th>
                                        <td style="text-align: center;"><#if aus.getLoginname()??>${aus.getLoginname()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getUsername()??>${aus.getUsername()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getPhone()??>${aus.getPhone()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getCityname()??>${aus.getCityname()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getCompanyname()??>${aus.getCompanyname()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getRolename()??>${aus.getRolename()}</#if></td>
                                        <td style="text-align: center;">
                                         	
                                         	<a id="editButton" onclick="showEditDiv('${aus.getId()}');" >编辑</a>
                                            
                                            <#if aus.getRolename()??   && aus.getRolename()!='superadmin'>
                                            <a onclick="doDeleteTableRow('${aus.getId()}');" >删除</a>
                                            </#if>
                                        </td>
                                    </tr>
                                    </#list>
                                    </tbody>
                                </table>
                                <div class="controls controls-row">
                                    <div id="Pagination" class="pagination"></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
  </div>
 
</body>
</html>

 
